package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//商品实体类
@Data
@JsonIgnoreProperties("handler")
public class Product extends BaseDomain {

    public static final Integer STATE_DOWN = 0; //下架
    public static final Integer STATE_UP = 1; //上架

    private String productName;//商品名称

    private String simpleInfo;//商品简介

    private String productImg;//商品图片

    private Integer state=STATE_UP;// 商品状态 默认上架

    private Integer price;//商品价格

    private String stock;//商品库存
    private  int count;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd ")
    private Date addTime;//添加时间

    private ProductInfo productInfo;//商品详细信息

    private ProductType productType;//商品分类

    public String getStateName() {
        String msg = "上架";
        if (state == STATE_DOWN) {
            msg = "下架";
        }
        return msg;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("productName", productName);
        map.put("simpleInfo", simpleInfo);
        map.put("productImg", productImg);
        map.put("state", state);
        map.put("price", price);
        map.put("stock", stock);
        if (productType!=null){
            map.put("productTypeId", productType.getId());
        }
        return JSONUtil.toJSONString(map);
    }

}